package com.dingnate.netty.client.demo;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import io.netty.handler.codec.http.*;
import io.netty.util.CharsetUtil;

public class HttpClientInboundHandler extends SimpleChannelInboundHandler<HttpObject> {

    public String getResponse() {
        return response;
    }

    private String response;

    @Override
    protected void channelRead0(ChannelHandlerContext ctx, HttpObject msg) throws Exception {
        if (msg instanceof HttpContent) {
            HttpContent content = (HttpContent) msg;
            ByteBuf buf = content.content();
            response = buf.toString(CharsetUtil.UTF_8);
        } else {
            System.out.println(msg);
        }
    }
}